#include "compl.h"

Compl::Compl()
{
    Re=0;
    Im=0;
}

Compl::Compl(double a, double b)
{
    Re=a;
    Im=b;

}

Compl Compl::operator*(Compl z)
{
    double x=Re*z.Re-z.Im*Im;
    double y=(Re*z.Im+Im*z.Re);
    return Compl(x,y);
};
Compl Compl::operator+(Compl z)
{
    double x=z.Re+Re;
    double y=z.Im+Im;
    return Compl(x,y);
};
Compl Compl::operator-(Compl z)
{
    double x=z.Re-Re;
    double y=z.Im-Im;
    return Compl(x,y);
};
Compl Compl::operator/(Compl z)
{
    double x=(z.Re*Re+z.Im*Im)/(Im*Im+Re*Re);
    double y=(Re*z.Im-z.Re*Im)/(Re*Re+Im*Im);
    return Compl(x,y);
}

std::ostream & operator<<(std::ostream &out, const Compl &x)
{
    if(x.Im>0)
    {
        out<<x.Re<<"+i"<<x.Im;
    }
    else
    {
        out<<x.Re<<"-i"<<-x.Im<<'\n';
    }
    return out;
};


